﻿using System;
using System.Configuration;
using Controllers;

namespace Web
{
    public partial class DeptList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            var depts = ctx.ExecuteQuery<DeptDTO>(@"with t as (select Id,Pid,cast(Text as nvarchar(500)) Text,Remarks,OrderNo,1 lvl,cast(OrderNo as nvarchar(50)) orderStr,IsValid from Depts where Pid is null
union all
select d.Id,d.Pid,cast(REPLICATE('---',t.lvl)+d.Text as nvarchar(500)),d.Remarks,
d.OrderNo,t.lvl+1,cast(t.orderStr+cast(d.OrderNo as nvarchar(50)) as nvarchar(50)),d.IsValid
from Depts d,t where d.Pid=t.id
)
select Id,Text,Remarks,OrderNo
,case when IsValid=1 then '有效' else '无效' end IsValid from t order by orderStr;");
            rptList.DataSource = depts;
            rptList.DataBind();
        }
    }
}